package com.meta.md.service.impl;

import com.meta.common.ConstDef;
import com.meta.md.service.MdService;
import com.meta.nd.dao.NvDAO;
import com.meta.nd.vo.Nv;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class MdServiceImpl implements MdService {
    @Resource
    NvDAO nvDAO;
    @Override
    public Nv getMd(String mdCode) {
        Nv nv = nvDAO.getSingleNvByCode(mdCode,ConstDef.FD_NAME_CODE, ConstDef.ND_CODE_MD);
        Nv rootNv = this.nvDAO.getNv(nv.getMetaNdCode(),nv.getId());
        return rootNv;
    }
    @Override
    public Nv getMv(String mdCode, String mvCode) {
        Nv rootNv = this.getMd(mdCode);
        List<Nv> mvs = rootNv.getSingleNvs();
        for( Nv mv : mvs ){
            String code = mv.getRawStringByName(ConstDef.FD_NAME_CODE);
            if ( code.equals(mvCode))
                return mv;
        }
        return null;
    }
}
